<?php
$servername = "localhost";
$username = "username";
$password = "password";
 
$dbname = "myDB";

// 创建连接，$dbname 是要连接的数据库
$conn = mysqli_connect($servername, $username, $password, $dbname);
// 检测连接
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}
 
// 创建数据库
// $sql = "CREATE DATABASE myDB";
// if (mysqli_query($conn, $sql)) {
//     echo "数据库创建成功";
// } else {
//     echo "Error creating database: " . mysqli_error($conn);
// }

// 使用 sql 创建数据表
// $sql = "CREATE TABLE MyGuests(
//     id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
//     firstname VARCHAR(30) NOT NULL,
//     lastname VARCHAR(30) NOT NULL,
//     email VARCHAR(50),
//     reg_date TIMESTAMP
// )";

// if (mysqli_query($conn,$sql)){
//     echo '数据表 MyGuests 创建成功';
// } else {
//     echo '创建数据表失败'.mysqli_error($conn);
// }
 

// 插入数据
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('tangzhu', 'murong', 'murong@email.com');";
$sql .= "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('ritian', 'zhao', 'ritian@email.com');";
$sql .= "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('canghai', 'ao', 'canghai@email.com')";


if (mysqli_multi_query($conn, $sql)) {
    echo '插入数据成功';
} else {
    echo 'Error'.$sql.'<br />'.mysqli_error($conn);
}


mysqli_close($conn);
?>